package com.alan.wifishare.view.impl.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alan.library.allog.KLog;
import com.alan.wifishare.R;
import com.alan.wifishare.presenter.SHAWifiSubmitPS;
import com.alan.wifishare.view.BaseActivity;
import com.alan.wifishare.view.impl.ActivityJumpUtil;
import com.alan.wifishare.view.iview.IVSHAWifiSubmit;

/**
 * @className: SHAWifiSubmitActivity
 * @describtion: SHAWifiSubmitActivity
 * @author: AlanWang
 * @email: 850267876@qq.com
 * @time: 2016/4/27 18:30
 */
public class SHAWifiSubmitActivity extends BaseActivity implements IVSHAWifiSubmit, View.OnClickListener {

    private SHAWifiSubmitPS shaWifiSubmitPS;
    private boolean isAdd;
    private int wifiId;
    private String wifiName;
    private String wifiPwd;
    private String wifiMac;
    private int wifiAreaId;
    private double wifiLongitude;
    private double wifiLatitude;
    private String wifiAddress;
    private Button shaWifiSubmitBackBtn;
    private RelativeLayout shaWifiSubmitSSIDRl;
    private TextView shaWifiSubmitSSIDTv;
    private EditText shaWifiSubmitPasswordEt;
    private TextView shaWifiSubmitAddressTv;
    private Button shaWifiSubmitSubmitBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.sha_wifi_submit_layout);
        shaWifiSubmitPS = new SHAWifiSubmitPS(this);
        initView();
    }

    @Override
    protected void initView() {
        shaWifiSubmitBackBtn = (Button)findViewById(R.id.shaWifiSubmitBackBtn);
        shaWifiSubmitBackBtn.setOnClickListener(this);
        shaWifiSubmitSSIDRl = (RelativeLayout)findViewById(R.id.shaWifiSubmitSSIDRl);
        shaWifiSubmitSSIDRl.setOnClickListener(this);
        shaWifiSubmitSSIDTv = (TextView)findViewById(R.id.shaWifiSubmitSSIDTv);
        shaWifiSubmitPasswordEt = (EditText)findViewById(R.id.shaWifiSubmitPasswordEt);
        shaWifiSubmitAddressTv = (TextView) findViewById(R.id.shaWifiSubmitAddressTv);
        shaWifiSubmitSubmitBtn = (Button)findViewById(R.id.shaWifiSubmitSubmitBtn);
        shaWifiSubmitSubmitBtn.setOnClickListener(this);

        Bundle bundle = getIntent().getExtras();
        isAdd = bundle.getBoolean(ActivityJumpUtil.Extra2SHAWifiSubmitAct.IS_ADD_WIFI);
        wifiId = bundle.getInt(ActivityJumpUtil.Extra2SHAWifiSubmitAct.WIFI_ID);
        wifiName = bundle.getString(ActivityJumpUtil.Extra2SHAWifiSubmitAct.WIFI_NAME);
        wifiPwd = bundle.getString(ActivityJumpUtil.Extra2SHAWifiSubmitAct.WIFI_PWD);
        wifiMac = bundle.getString(ActivityJumpUtil.Extra2SHAWifiSubmitAct.WIFI_MAC);
        wifiAreaId = bundle.getInt(ActivityJumpUtil.Extra2SHAWifiSubmitAct.WIFI_AREA_ID);
        wifiLongitude = bundle.getDouble(ActivityJumpUtil.Extra2SHAWifiSubmitAct.WIFI_LONGITUDE);
        wifiLatitude = bundle.getDouble(ActivityJumpUtil.Extra2SHAWifiSubmitAct.WIFI_LATITUDE);
        wifiAddress = bundle.getString(ActivityJumpUtil.Extra2SHAWifiSubmitAct.WIFI_ADDRESS);
        shaWifiSubmitSSIDTv.setText(wifiName);
        shaWifiSubmitPasswordEt.setText(wifiPwd);
        shaWifiSubmitAddressTv.setText(wifiAddress);
    }

    @Override
    public int getWifiId() {
        return 0;
    }

    @Override
    public String getWifiSSID() {
        return shaWifiSubmitSSIDTv.getText().toString();
    }

    @Override
    public String getWifiPassword() {
        return shaWifiSubmitPasswordEt.getText().toString();
    }

    @Override
    public String getWifiAdressStr() {
        return shaWifiSubmitAddressTv.getText().toString();
    }

    @Override
    public int getAreaId() {
        return wifiAreaId;
    }

    @Override
    public String getWifiMac() {
        return wifiMac;
    }

    @Override
    public int getWifiAreaId() {
        return wifiAreaId;
    }

    @Override
    public double getWifiLongitude() {
        return wifiLongitude;
    }

    @Override
    public double getWifiLatitude() {
        return wifiLatitude;
    }

    @Override
    public void showProgress() {
        progressDialogShow();
    }

    @Override
    public void hideProgress() {
        progressDialogHiden();
    }

    @Override
    public void toastMsg(String msg) {
        toastMsgShort(msg);
    }

    @Override
    public void submitSuccess() {
        KLog.e();
        SHAWifiSubmitActivity.this.setResult(RESULT_OK);
        SHAWifiSubmitActivity.this.finish();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.shaWifiSubmitBackBtn:
                SHAWifiSubmitActivity.this.finish();
                break;
            case R.id.shaWifiSubmitSSIDRl:
                break;
            case R.id.shaWifiSubmitSubmitBtn:
                toastMsg(isAdd ? "增加Wifi" : "修改Wifi");
                if(isAdd){
                    shaWifiSubmitPS.postAddWifi();
                }else {
                    shaWifiSubmitPS.postUpdateWifi();
                }
                break;
            default:
                break;
        }
    }
}
